package com.rm.zeyou.pay.wxpay.controller;


import com.rm.zeyou.pay.wxpay.service.WeChatNotifyService;
import com.rm.zeyou.pay.wxpay.vo.WxPayAsyncReturnVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.GeneralSecurityException;


/**
 * @author ZhangKeChen
 * @date 2022/8/19
 */
//@Slf4j
@RestController
@RequestMapping("/api/wechat")
public class WeChatNotifyController {
    @Resource
    private WeChatNotifyService weChatPayService;

    /**
     * 常规服务订单回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/notify")
    public WxPayAsyncReturnVo notify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return weChatPayService.notify(request, response);
    }

    /**
     * 升级服务订单回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/upgradeNotify")
    public WxPayAsyncReturnVo upgradeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return weChatPayService.upgradeNotify(request, response);
    }

    /**
     * 加钟服务订单回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/bellNotify")
    public WxPayAsyncReturnVo bellNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return weChatPayService.bellNotify(request, response);
    }

    /**
     * 开通会员订单支付回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/rechargeNotify")
    public WxPayAsyncReturnVo rechargeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return weChatPayService.rechargeNotify(request, response);
    }


    /**
     * 获取用户openid回调
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @GetMapping("/wechatNotify")
    public String wechatNotify(HttpServletRequest request, HttpServletResponse response)  {
        return weChatPayService.wechatNotify(request, response);
    }

}
